﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'upload', 'form', 'laydate', 'common', 'optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common,
            upload = layui.upload,
            laydate = layui.laydate;
        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('adminform');
        var isUpload = false;
        var postData = {};
        //此处需修改
        //类型为时间时
        laydate.render({
            elem: '#F_EndTime'
            , btns: ['clear', 'now']
            , trigger: 'click',
            format: 'yyyy-MM-dd',
        });
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/FileManage/Uploadfile/Upload' //改成您自己的上传接口
            , size: 1024
            , accept: 'file'
            , data: { filetype: 1, fileby: '公司logo' }
            , auto: false//不自动提交
            , bindAction: "#hideupload1"//绑定真正提交的按钮
            , choose: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
                isUpload = true;//判断是否已上传，用于表单提交中控制跳转
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    //失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                    common.modalMsg(res.msg, "warning");
                    return false;
                }
                postData.F_Logo = res.data[0].src;
                //上传成功
                common.submitForm({
                    url: '/SystemOrganize/SystemSet/SetSubmitForm',
                    param: postData,
                    success: function () {
                        common.parentreload('data-search-btn');
                    }
                })
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
        $(function () {
            if (!!keyValue) {
                common.ajax({
                    url: '/SystemOrganize/SystemSet/GetFormJson',
                    dataType: 'json',
                    async: false,
                    data: { keyValue: keyValue },
                    success: function (data) {
                        common.val('adminform', data);
                        $('#F_EndTime').val(new Date(data.F_EndTime).Format("yyyy-MM-dd"));
                        $('#demo1').attr('src', data.F_Logo); //图片链接
                    }
                });
            }
            form.render();
        });
        wcLoading.close();
        //监听提交
        form.on('submit(saveBtn)', function (data) {
                postData = data.field;
                if (isUpload) {
                    $("#hideupload1").trigger('click');
                }
                else {
                    common.submitForm({
                        url: '/SystemOrganize/SystemSet/SetSubmitForm',
                        param: postData,
                        success: function () {
                            common.parentreload('data-search-btn');
                        }
                    })
                }
            return false;
        });
    });
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_ProjectName" name="F_ProjectName" maxlength="50" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">公司名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_CompanyName" name="F_CompanyName" maxlength="50" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">联系人</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_PrincipalMan" name="F_PrincipalMan" maxlength="50" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">联系方式</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_MobilePhone" name="F_MobilePhone" autocomplete="off" lay-verify="required|phone" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required" style="margin-top: 50px;">Logo图标</label>
                        <div class="layui-input-block" style="padding-right: 0px;">
                            <input class="layui-hide" hidden type="text" id="F_Logo" name="F_Logo">
                            <div class="layui-upload-list">
                                <img class="layui-upload-img" id="demo1">
                                <p id="demoText"></p>
                            </div>
                        </div>
                        <button type="button" class="layui-btn" id="test1" style="position: absolute;top: 0;right: 6px;cursor: pointer;margin-top: 50px;">选择</button>
                        <button type="button" class="layui-hide" id="hideupload1">上传</button>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">Logo编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_LogoCode" name="F_LogoCode" maxlength="50" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">系统账户</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_AdminAccount" name="F_AdminAccount" maxlength="50" autocomplete="off" readonly lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">系统密码</label>
                        <div class="layui-input-block">
                            <input type="password" id="F_AdminPassword" name="F_AdminPassword" maxlength="50" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">有效</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="F_EnabledMark" id="F_EnabledMark" checked="" value="true" title="有效标识">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">到期时间</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_EndTime" name="F_EndTime" autocomplete="off" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">域名</label>
                        <div class="layui-input-block">
                            <textarea id="F_HostUrl" name="F_HostUrl" class="layui-textarea" autocomplete="off" maxlength="50" lay-verify="required" placeholder="请输入域名"></textarea>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea id="F_Description" name="F_Description" class="layui-textarea" placeholder="请输入备注"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>

